﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using ZLDC.DAL.Estate;
using ZLDC.Common.Estate;
using ZLDC.Common.BaseUser;

namespace ZLDC.Topo.BLL.Estate
{
    public class AlertBLL
    {
        public static string GetAllAlert(int page, int pagesize, int userid, int deptid)
        {
            int total = 0;
            DataTable dt = new DataTable();
            string deptids = UserInfo.getGetAllFatherDeptAllUsers(deptid);
            string condition = string.Empty;
            condition += " where (AlertScope=0";
            condition += "  or (AlertScope=1 and AddUserId ='"+userid+"')";
            condition += " or (AlertScope=2 and AddDeptId in (" + deptids + "))) and dltFlag=0";
            using (_Database db = new _Database("estate"))
            {
                dt = HousingAlertDAL.GetAllAlert(page, pagesize, condition, ref total, db);
            }

            _Json json = new _Json(dt);

            int pageall = _Utility.GetPageAll(pagesize, total);                  return "{page:{currentpage:'" + page + "',pagesize:'" + pagesize + "',total:'" + total + "',pageall:'" + pageall + "'},record:" + json.ToJson() + "}";
        }

                                                                        public static string GetTodayAlert(int page, int pagesize, int userid, int deptid)
        {
            int total = 0;
            DataTable dt = new DataTable();
            string deptids = UserInfo.getGetAllFatherDeptAllUsers(deptid);
            string condition = string.Empty;

            condition += " where ((AlertScope=1 and AddUserId ='" + userid + "') or (AlertScope=2 and AddDeptId in (" + deptids + "))) ";         
                       condition += " and alertDate<='" + DateTime.Today.ToString("yyyy-MM-dd") + " 23:59:59' and dltFlag=0  and (dFlag=0 or dFlag is null)";
            using (_Database db = new _Database("estate"))
            {
                dt = HousingAlertDAL.GetAllAlert(page, pagesize, condition, ref total, db);
            }

            _Json json = new _Json(dt);

            int pageall = _Utility.GetPageAll(pagesize, total);                  return "{page:{currentpage:'" + page + "',pagesize:'" + pagesize + "',total:'" + total + "',pageall:'" + pageall + "'},record:" + json.ToJson() + "}";
        }

        public static string GetHousingAlert(string condition, string subsidiary)
        {
                        DataTable dt = new DataTable();
            using (_Database db = new _Database("estate"))
            {
                dt = HousingAlertDAL.GetWillToDatum(condition,subsidiary, db);
            }
            _Json json = new _Json(dt);

                        DataTable dt1 = new DataTable();
            using (_Database db = new _Database("estate"))
            {
                dt1 = HousingAlertDAL.GetInformAlert(condition, db);
            }
            _Json json1 = new _Json(dt1);

                        DataTable dt2 = new DataTable();
            using (_Database db = new _Database("estate"))
            {
                dt2 = HousingAlertDAL.GetWillToDatum1(condition, db);
            }
            _Json json2 = new _Json(dt2);

            return "{record:" + json.ToJson() + ",record1:" + json1.ToJson() + ",record2:" + json2.ToJson() + " }";
        }
        public static string GetCustomerAlert(string condition)
        {
            DataTable dt = new DataTable();
            using (_Database db = new _Database("estate"))
            {
                dt = CustomerDAL.GetWillToPublic(condition, db);
            }
            _Json json = new _Json(dt);

            
            return "{record:" + json.ToJson() + " }";
        }

       
    }
}
